package com.screen.screendisplay.service.impl.electric;

import com.screen.screendisplay.entity.electric.ElectricProdoperCoalConsume;
import com.screen.screendisplay.mapper.electric.ElectricProdoperCoalConsumeMapper;
import com.screen.screendisplay.service.electric.ElectricProdoperCoalConsumeService;
import com.screen.screendisplay.vo.electric.CoalConsumeTrendDto;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;
import java.util.stream.Collectors;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

/**
 * <p>
 * 供电煤耗趋势表 服务实现类
 * </p>
 *
 * @author xuesong
 * @since 2025-08-23
 */
@Service
public class ElectricProdoperCoalConsumeServiceImpl extends ServiceImpl<ElectricProdoperCoalConsumeMapper, ElectricProdoperCoalConsume> implements ElectricProdoperCoalConsumeService {


    /**
     * 供电煤耗趋势
     * @return 只包含年份、月份、当日耗煤量、去年同期耗煤量的DTO列表
     */
    @Override
    public List<CoalConsumeTrendDto> prodoperCoalConsume() {
        int currentYear = LocalDate.now().getYear();
        int lastYear = currentYear - 1;
        
        QueryWrapper<ElectricProdoperCoalConsume> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("year", lastYear, currentYear)
                .orderByAsc("year", "record_date");
        
        List<ElectricProdoperCoalConsume> entityList = this.list(queryWrapper);
        
        // 转换为DTO对象列表，只包含需要的字段
        return entityList.stream()
                .map(entity -> {
                    CoalConsumeTrendDto dto = new CoalConsumeTrendDto();
                    dto.setYear(entity.getYear());
                    dto.setMonth(entity.getMonth());
                    dto.setCoalConsumption(entity.getCoalConsumption());
                    dto.setLastYearCoalConsumption(entity.getLastYearCoalConsumption());
                    return dto;
                })
                .collect(Collectors.toList());
    }

}
